import axios from 'axios'
import {MessageBox,Message} from "element-ui";
import cookie from 'js-cookie'
// 创建axios实例
const service = axios.create({
  baseURL: 'http://localhost:9001', // api的base_url
  timeout: 20000 // 请求超时时间
})

service.interceptors.request.use(
  config => {
    if (cookie.get('guli_token')) {
      config.headers['token'] = cookie.get('guli_token');
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }

)
service.interceptors.response.use(
  response => {
    if (response.data.code !== 20000) {
      Message({
        message:response.data.message||'error',
        type:'error',
        duration:5*1000
      })
    }
    return response
  }

)


export default service
